<template>
  <a-upload-dragger :ref="cell.editorRef" :action="action" :headers="headers" @change="handleChange"> 点击或拖拽到这里 </a-upload-dragger>
</template>
<script setup lang="ts">
import { message } from "ant-design-vue";
import type { CellEditorArgs } from "@surely-vue/table/dist/src/components/interface";
import {post, token} from "@/common";

const props = defineProps({
  action: {
    default: "",
  },
  cell: {
    default: {} as CellEditorArgs,
  },
});

const headers = {
  Authorization:`Bearer ${token.value}`,
  Accept: 'application/json, text/plain, */*',
  'X-Requested-With': null,
} as any
const data = {
  url:"upload"
}
const handleChange = async (info: any) => {
  const status = info.file.status;
  const { modelValue, save, closeEditor } = props.cell;
  if (status === "done") {
    message.success(`${info.file.name} 上传成功！`);

    await post("v1/file/delete", {data: modelValue.value})

    modelValue.value = info.file.response;
    save();
    closeEditor();
  } else if (status === "error") {
    message.error(`${info.file.name} 上传失败`);
  }
};
</script>
